package wordeditor.actions;

import java.io.File;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

import wordeditor.utils.EclipseUtils;
import wordeditor.utils.ExpandFileMots;

public class ConverterAction implements IObjectActionDelegate {

	private Shell shell;
	
	/**
	 * Constructor for Action1.
	 */
	public ConverterAction() {
		super();
	}

	/**
	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
	*/
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		shell = targetPart.getSite().getShell();
	}

	/**
	 * @see IActionDelegate#run(IAction)
	*/
	public void run(IAction action) {
		System.out.println("action.." ) ;
		IFile ifileSrc = EclipseUtils.getFileSelected();
		if (ifileSrc != null) {
			System.out.println("action fichier=" + ifileSrc.toString() ) ;
        	IProject project = ifileSrc.getProject();		        	
        	String path  = ifileSrc.getRawLocation().toOSString();
        	File fileSrc = new File(path) ;
        	ExpandFileMots.expandFile(path);
        	System.out.println("expansion fichier=" + ifileSrc.toString() ) ;
        	EclipseUtils.refreshFile(fileSrc,ifileSrc.getParent(),project );
		}
		
		
		
	}

	/**
	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
	 */
	public void selectionChanged(IAction action, ISelection selection) {
	}

}
